import type { ShiftUnit } from '@/types'

export function joinUser(
  userName: string,
  loginName: string,
) {
  return `${userName}${
    loginName ? `（${loginName}）` : ''
  }`
}

export function joinTime(s: string, end: string) {
  return `${s || ''} - ${end || ''}`
}

export function splitTime(s: string) {
  if (!s)
    return {}
  const ss = (s || '').replace(/\s/g, '').split('-')
  return {
    startTime: ss[0],
    endTime: ss[1],
  }
}

export function transformUser(
  v: any,
): Omit<ShiftUnit, 'id' | 'name' | 'details'> {
  return {
    creatorUserId: v.creationId,
    creatorUserName: v.creationUserName,
    creatorLoginName: v.creationLoginName,
    creationTime: v.creationTime,
    updatorUserId: v.updateId,
    updatorUserName: v.updateUserName,
    updatorLoginName: v.updateLoginName,
    updateTime: v.updateTime,
  }
}
